define(['../../../../../js/lib/other/sweet-alert'],function() {
    return ['$scope','$location', '$interval','$timeout','$routeParams','bizProxy', function($scope,$location,$interval,$timeout,$routeParams,bizProxy) {
		$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','32');//显示底部文字
    	
    	//获取参数applyId
    	if($routeParams.flag != "" && $routeParams.flag != null){
    		queryMyLoan($routeParams.flag);
    	}
    	//默认选项
    	var guarantee = '0';//0:担保  1:不担保
    	$scope.isno_slt = false,$scope.isSlide_up = false,$scope.agrshow_block = false,$scope.refshow_block = false;
    	$scope.password = _YHC_util.strToArr(""),$scope.refuseContent = "";
    	
    	var tempRandom = 2.6,tempPassword = "";
    	
    	//监听子集显示顶部显示
        $scope.$on('pwdChange', function(event, data) {
        	$timeout(function(){
        		if(data.length == 6){
        			tempPassword = data;
        		}
        		$scope.password = _YHC_util.strToArr(data);
        	},0);
        });
    	
    	//点击获取密码数据
    	$scope.getPassword = function(){
    		$scope.$emit("pwdSlidUp",tempRandom++);
    	}
    	
    	//点击是否要担保
    	$scope.ensureFn = function(){
    		if($scope.isno_slt){
        		$scope.isno_slt = false;
        	}else{
        		$scope.isno_slt = true;
        	}
    	}
    	
    	$scope.$watch('password', function() {
    		if(($scope.password)[5] != ""){
    			$scope.$emit("pwdSlidUp",'0');
    		}
		});
    	
    	//点击拒绝
    	$scope.refuseFn = function(){
    		$scope.isSlide_up = true,$scope.agrshow_block = false,$scope.refshow_block = true;
    	}
    	
    	//点击同意贷款申请
    	$scope.agreeLoan = function(){
    		if($scope.isno_slt){
    			guarantee = '1'
    		}else{
    			guarantee = '0'
    		}
    		checkLoanApplyData.loanApplyId = $routeParams.flag;
        	checkLoanApplyData.approveContent = "T";
        	checkLoanApplyData.isGuarntee = guarantee;
    	
			$scope.$emit("goNext","/loanSurvey");
			//$scope.$emit("goNext","/loanSurvey/"+applyId +"/"+guarantee);
    		//$scope.isSlide_up = true,$scope.agrshow_block = true,$scope.refshow_block = false;
    	}
    	
    	
    	//点击确认同意
    	$scope.agreConfirm = function(){
    		if(! tempPassword){
    			$scope.$emit("promptAlertMsg","请输入密码");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}
    		
    		var headerInfo = {},sendData = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
    		
        	sendData.loginType = "password";
    		sendData.mobileNo = transData.mobileNo;
    		sendData.password = tempPassword;
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("userLogin",headerInfo,sendData,
    				function(tempData){//SUCCESS
    					$scope.$emit("loadingChange",false);
    					localStorage.setItem("fireFlySessionId",tempData.sessionId+"");
    					agreeLoanApply("T","");
		    		},function(data){//FAIL
		    			$scope.$emit("loadingChange",false);
//		    			FIREFLY("", "密码输入错误","",function(){});
		    			$scope.$emit("promptAlertMsg","密码输入错误");
		    			$scope.$emit("showCollect",true);
		    			$timeout(function(){
		    				$scope.$emit("showCollect",false);
		    			},transData.promptTime);
		    		});
    	}
    	
    	//点击确认拒绝
    	$scope.refuConfirm = function(){
    		if(! $scope.refuseContent){
    			$scope.$emit("promptAlertMsg","请填写拒绝理由");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}else{
    			agreeLoanApply("F",$scope.refuseContent);
    		}
    	}
    	
    	//点击关闭弹出层
    	$scope.closeDiv = function(){
    		$scope.$emit("pwdSlidUp",-1);
    		$scope.isSlide_up = false,$scope.agrshow_block = false,$scope.refshow_block = false;
    	}
    	
    	
    	//同意贷款申请
    	function agreeLoanApply(flag,reason){
    		if($scope.isno_slt){
    			guarantee = '1'
    		}else{
    			guarantee = '0'
    		}
    		
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.loanApplyId = $routeParams.flag;
        	bizInfo.approveContent = flag;
        	bizInfo.isGuarntee = guarantee;
        	
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("approveLoan",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			$timeout(function(){
							$scope.$emit("loadingChange",false);
							
							$scope.$emit("goNext","/refuseLoan");
							
							
						},0);
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
									history.back();
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChange', false);
		    				$scope.$emit("promptAlertMsg",data.errorMsg);
							$scope.$emit("showCollect",true);
							$timeout(function(){
								$scope.$emit("showCollect",false);
								history.back();
							},transData.promptTime);
		    			}
		    		});
    	}
    	
    	//代理查询我的贷款概要
    	function queryMyLoan(applyId){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.applyId = applyId;
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("queryLoanApplyOutline",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			if(tempData.body != "" && tempData.body != null && tempData.body != "[]"){
							$timeout(function(){
								$scope.$emit("loadingChange",false);
								var myLoanList = JSON.parse(tempData.body);
								$scope.myLoanData = myLoanList;
							},0);
						}else{
							$scope.$emit("loadingChange",false);
							$scope.$emit("promptAlertMsg","未查找到相关数据");
							$scope.$emit("showCollect",true);
							$timeout(function(){
								$scope.$emit("showCollect",false);
								history.back();
							},transData.promptTime);
						}
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
									history.back();
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChange', false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    					history.back();
		    				},transData.promptTime);
		    			}
		    		});
    	}
    	
    	//当键盘被销毁的时候
        $scope.$on("$destroy", function() {
        	$scope.$emit("pwdSlidUp","");
	    });
        $scope.$apply();
    }];
});